namespace Ds.DataBase.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class _20200630001 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.ZhiWeis", "keshi_ksid", "dbo.KeShis");
            DropForeignKey("dbo.KaoHeFanWeiZhiWeis", "KaoHeFanWei_khfwid", "dbo.KaoHeFanWeis");
            DropForeignKey("dbo.KaoHeFanWeiZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.MoBanZhiWeis", "MoBan_mbid", "dbo.MoBans");
            DropForeignKey("dbo.MoBanZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropIndex("dbo.ZhiWeis", new[] { "keshi_ksid" });
            DropIndex("dbo.KaoHeFanWeiZhiWeis", new[] { "KaoHeFanWei_khfwid" });
            DropIndex("dbo.KaoHeFanWeiZhiWeis", new[] { "ZhiWei_zwid" });
            DropIndex("dbo.MoBanZhiWeis", new[] { "MoBan_mbid" });
            DropIndex("dbo.MoBanZhiWeis", new[] { "ZhiWei_zwid" });
            CreateTable(
                "dbo.KeShiZhiWeis",
                c => new
                    {
                        KeShi_ksid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.KeShi_ksid, t.ZhiWei_zwid })
                .ForeignKey("dbo.KeShis", t => t.KeShi_ksid, cascadeDelete: true)
                .ForeignKey("dbo.ZhiWeis", t => t.ZhiWei_zwid, cascadeDelete: true)
                .Index(t => t.KeShi_ksid)
                .Index(t => t.ZhiWei_zwid);
            
            AddColumn("dbo.ZhiWeis", "KaoHeFanWei_khfwid", c => c.Int());
            AddColumn("dbo.ZhiWeis", "MoBan_mbid", c => c.Int());
            CreateIndex("dbo.ZhiWeis", "KaoHeFanWei_khfwid");
            CreateIndex("dbo.ZhiWeis", "MoBan_mbid");
            AddForeignKey("dbo.ZhiWeis", "KaoHeFanWei_khfwid", "dbo.KaoHeFanWeis", "khfwid");
            AddForeignKey("dbo.ZhiWeis", "MoBan_mbid", "dbo.MoBans", "mbid");
            DropColumn("dbo.ZhiWeis", "keshi_ksid");
            DropTable("dbo.KaoHeFanWeiZhiWeis");
            DropTable("dbo.MoBanZhiWeis");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.MoBanZhiWeis",
                c => new
                    {
                        MoBan_mbid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MoBan_mbid, t.ZhiWei_zwid });
            
            CreateTable(
                "dbo.KaoHeFanWeiZhiWeis",
                c => new
                    {
                        KaoHeFanWei_khfwid = c.Int(nullable: false),
                        ZhiWei_zwid = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.KaoHeFanWei_khfwid, t.ZhiWei_zwid });
            
            AddColumn("dbo.ZhiWeis", "keshi_ksid", c => c.Int());
            DropForeignKey("dbo.ZhiWeis", "MoBan_mbid", "dbo.MoBans");
            DropForeignKey("dbo.ZhiWeis", "KaoHeFanWei_khfwid", "dbo.KaoHeFanWeis");
            DropForeignKey("dbo.KeShiZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis");
            DropForeignKey("dbo.KeShiZhiWeis", "KeShi_ksid", "dbo.KeShis");
            DropIndex("dbo.KeShiZhiWeis", new[] { "ZhiWei_zwid" });
            DropIndex("dbo.KeShiZhiWeis", new[] { "KeShi_ksid" });
            DropIndex("dbo.ZhiWeis", new[] { "MoBan_mbid" });
            DropIndex("dbo.ZhiWeis", new[] { "KaoHeFanWei_khfwid" });
            DropColumn("dbo.ZhiWeis", "MoBan_mbid");
            DropColumn("dbo.ZhiWeis", "KaoHeFanWei_khfwid");
            DropTable("dbo.KeShiZhiWeis");
            CreateIndex("dbo.MoBanZhiWeis", "ZhiWei_zwid");
            CreateIndex("dbo.MoBanZhiWeis", "MoBan_mbid");
            CreateIndex("dbo.KaoHeFanWeiZhiWeis", "ZhiWei_zwid");
            CreateIndex("dbo.KaoHeFanWeiZhiWeis", "KaoHeFanWei_khfwid");
            CreateIndex("dbo.ZhiWeis", "keshi_ksid");
            AddForeignKey("dbo.MoBanZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.MoBanZhiWeis", "MoBan_mbid", "dbo.MoBans", "mbid", cascadeDelete: true);
            AddForeignKey("dbo.KaoHeFanWeiZhiWeis", "ZhiWei_zwid", "dbo.ZhiWeis", "zwid", cascadeDelete: true);
            AddForeignKey("dbo.KaoHeFanWeiZhiWeis", "KaoHeFanWei_khfwid", "dbo.KaoHeFanWeis", "khfwid", cascadeDelete: true);
            AddForeignKey("dbo.ZhiWeis", "keshi_ksid", "dbo.KeShis", "ksid");
        }
    }
}
